package lenfs;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import lenfs.util.XDR;
import lenfs.util.constants.NFSConst;


import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;

public class Main {

	public static void main(String[] args) {
		final Server server = new Server();

		ChannelFactory factory = new NioDatagramChannelFactory(
				Executors.newCachedThreadPool());

		ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);

		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			public ChannelPipeline getPipeline() {
				return Channels.pipeline(new ServerHandler(server));
			}
		});

		bootstrap.setOption("receiveBufferSizePredictorFactory",
				new FixedReceiveBufferSizePredictorFactory(NFSConst.MAXDATA
						+ XDR.UNIT * 64));

		bootstrap.bind(new InetSocketAddress(8080));
	}
}
